package com.wushi.lenovo.asia5b.app_ui.shopcar.adapter;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mvp.images.WImageLoader;
import com.mvp.utils.ResString;
import com.wushi.lenovo.asia5b.R;
import com.wushi.lenovo.asia5b.app_model.good.bean.PriceDetailType;
import com.wushi.lenovo.asia5b.app_model.good.goodbean.GoodsModelIml;
import com.wushi.lenovo.asia5b.app_model.good.goodbean.OrderGoodBean;
import com.wushi.lenovo.asia5b.app_ui.h5.GoodsDetailsActivity;
import com.wushi.lenovo.asia5b.app_ui.orderdetail.PriceDetailActivity;
import com.wushi.lenovo.asia5b.app_widget.mingan.MinganImageView;

import java.util.List;

/**
 * Created by zhangyuncai on 2020/3/2.
 */
public class OrderPackGoodsAdapter<GOOD extends GoodsModelIml> extends BaseQuickAdapter<GOOD, BaseViewHolder> {
    public List<OrderGoodBean> inputGoods;//todo 查看包裹详情统一用订单列表的数据

    public OrderPackGoodsAdapter(@Nullable List<GOOD> data) {
        super(R.layout.item_ordepack_goodsadapter, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GOOD item) {
        //商品信息
        setGoodView(helper, item);

        //价格详细
        helper.getView(R.id.view_goods_pricedetail).setOnClickListener(v -> {
            for (OrderGoodBean inputGood : inputGoods) {
                if (inputGood.getId() == item.parcelno()) {
                    PriceDetailActivity.startPriceDetailActivity(mContext, inputGood, PriceDetailType.orderpack);
                    break;
                }
            }
        });
        //商品详细
        helper.getView(R.id.mingan_goods).setOnClickListener(v -> {
            GoodsDetailsActivity.startGoodsDetailsActivity(mContext, item.goodsId());
        });
    }


    /**
     * 设置商品信息
     *
     * @param helper
     * @param item   商品数据
     */
    private void setGoodView(BaseViewHolder helper, GOOD item) {
        //商品名
        TextView tv_goods_goodname = helper.getView(R.id.tv_goods_goodname);
        tv_goods_goodname.setText(item.goodsName());
        tv_goods_goodname.setOnClickListener(v -> {
            GoodsDetailsActivity.startGoodsDetailsActivity(mContext, item.goodsId());
        });

        //商品图片
        MinganImageView mingan_goods = helper.getView(R.id.mingan_goods);
        WImageLoader.displayImage(mContext, item.goodsImg(), mingan_goods.getImageView());

        //包裹编号
        TextView tv_goods_goodno = helper.getView(R.id.tv_goods_goodno);
        tv_goods_goodno.setText(String.format("%s:%d", ResString.get(R.string.parcelno), item.parcelno()));

        //价格
        TextView tv_goods_price = helper.getView(R.id.tv_goods_price);
        tv_goods_price.setText(String.format("%s        x %d", item.goodsUnitPrice(), item.goodsQuantity()));

    }
}
